package com.sugon.controller.device;

import com.sugon.entity.FaultBaseEntity;
import com.sugon.service.FaultBaseService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备故障库Controller
 *
 * @author sugon
 * @date 2019-07-31 16:38:41
 */
@Controller
@RequestMapping("faultbase")
public class FaultBaseController {
    @Autowired
    private FaultBaseService faultBaseService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {

        //查询列表数据
        Query query = new Query(params);

        List<FaultBaseEntity> faultBaseList = faultBaseService.queryList(query);
        int total = faultBaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(faultBaseList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        FaultBaseEntity faultBase = faultBaseService.queryObject(id);

        return R.ok().put("faultBase", faultBase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("faultbase:save")
    @ResponseBody
    public R save(@RequestBody FaultBaseEntity faultBase) {
        faultBaseService.save(faultBase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("faultbase:update")
    @ResponseBody
    public R update(@RequestBody FaultBaseEntity faultBase) {
        faultBaseService.update(faultBase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("faultbase:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        faultBaseService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<FaultBaseEntity> list = faultBaseService.queryList(params);

        return R.ok().put("list", list);
    }
}
